const httpbinInstance = require('../utils/request');
const constant = require('./constant');
const storage = require('../utils/storage');
// 获取手机验证码
export const getPhoneCode = (phone) => {
  return new Promise((resolve,reject) => {
    httpbinInstance.request({
      url:'/user/postmobile',
      method:'post',
      data:{
        mobile: phone
      }
      }).then(res => {
        resolve(res)
      })
   })
}
// 用户注册
export const register = (queryform) => {
  return new Promise((resolve,reject) => {
    httpbinInstance.request({
      url:'/user/addusermobile',
      method:'post',
      data:{
        ...queryform
      }
      }).then(res => {
        resolve(res)
      })
   })
}
// 账号密码登陆
export const login = (queryform) => {
  return new Promise((resolve,reject) => {
    httpbinInstance.request({
      url:'/login/system',
      method:'post',
      data:{
        ...queryform
      }
      }).then(res => {
        resolve(res)
      })
   })
}
// 获取code换存token
// export const wechatLogin = () => {
//   return new Promise((resolve,reject) => {
//     wx.login({
//       success: res => {
//         if(res.code && res.code != ''){
//           resolve(res);
//         }
//       },
//       fail:res => {
//       }
//     })
//   })
// }
// 获取微信登陆
export const wechatLogin = (queryform) => {
  return new Promise((resolve,reject) => {
    wx.request({
      url: constant.BASEURL + '/login/wechat',
      method:'post',
      data: {...queryform},
      header: {'Authorization':'Bearer ','Deviceid':'loveqing'},
      success: res => {  // code:50005 token过期
        // 存token
        storage.setJwtToken(res.data.data.token)
        resolve(res.data)
      },
      fail: err => {
        reject(err)
      },
      complete:()=>{
        // wx.hideLoading()
      }
    })
})
}
// 手机验证码登陆
export const phoneLogin = (queryform) => {
  return new Promise((resolve,reject) => {
    httpbinInstance.request({
      url:'/login/mobile',
      method:'post',
      data:{
        ...queryform
      }
      }).then(res => {
        resolve(res)
      })
   })
}
// 账号密码登录
export const passwordLogin = (username,password) => {
  return new Promise((resolve,reject) => {
    httpbinInstance.request({
      url:'/login/system',
      method:'post',
      data:{
        identifier: username,
        credential: password
      }
      }).then(res => {
        resolve(res)
      })
   })
}
// 实名认证(第一步)：获取活体行为
export const behavior = () => {
  return new Promise((resolve,reject) => {
    httpbinInstance.request({
      url:'/user/behavior',
      method:'post',
      data:{}
      }).then(res => {
        resolve(res)
      })
   })
}
// 实名认证(第二步)：获取活体行为
export const verify = (queryform) => {
  return new Promise((resolve,reject) => {
    httpbinInstance.request({
      url:'/user/verify',
      method:'post',
      data:{
        ...queryform
      }
      }).then(res => {
        resolve(res)
      })
   })
}
// 用户身份
export const getUserIdentity = () => {
  return new Promise((resolve,reject) => {
    httpbinInstance.request({
      url:'/store/if',
      method:'post',
      data:{}
      }).then(res => {
        resolve(res)
      })
   })
}
// 仓库列表
export const getStoreList = (queryform) => {
  return new Promise((resolve,reject) => {
    httpbinInstance.request({
      url:'/store/lists',
      method:'post',
      data:{
        ...queryform
      }
      }).then(res => {
        resolve(res)
      })
   })
}
// 商户入驻
export const posAdd = (queryform) => {
  return new Promise((resolve,reject) => {
    httpbinInstance.request({
      url:'/pos/add',
      method:'post',
      data:{
        ...queryform
      }
      }).then(res => {
        resolve(res)
      })
   })
}
// 添加仓库
export const addStore = (queryform) => {
  return new Promise((resolve,reject) => {
    httpbinInstance.request({
      url:'/store/add',
      method:'post',
      data:{
        ...queryform
      }
      }).then(res => {
        resolve(res)
      })
   })
}
// 首页借出
export const lendLists = (queryform) => {
  return new Promise((resolve,reject) => {
    httpbinInstance.request({
      url:'/lend/lend_lists',
      method:'post',
      data:{
        ...queryform
      }
      }).then(res => {
        resolve(res)
      })
   })
}
// 首页借入
export const borrowLists = (queryform) => {
  return new Promise((resolve,reject) => {
    httpbinInstance.request({
      url:'/lend/borrow_lists',
      method:'post',
      data:{
        ...queryform
      }
      }).then(res => {
        resolve(res)
      })
   })
}
// 仓库详情
export const storeDetails = (queryform) => {
  return new Promise((resolve,reject) => {
    httpbinInstance.request({
      url:`/store/show/store_id/${queryform}`,
      method:'get',
      data:{
      }
      }).then(res => {
        resolve(res)
      })
   })
}
// 修改仓库
export const updateStore = (queryform) => {
  return new Promise((resolve,reject) => {
    httpbinInstance.request({
      url:'/store/update',
      method:'post',
      data:{
        ...queryform
      }
      }).then(res => {
        resolve(res)
      })
   })
}
// 删除仓库
export const deleteStore = (queryform) => {
  return new Promise((resolve,reject) => {
    httpbinInstance.request({
      url:'/store/delete',
      method:'post',
      data:{
        ...queryform
      }
      }).then(res => {
        resolve(res)
      })
   })
}
// 获取标签列表
export const getNoteListData = (queryform) => {
  return new Promise((resolve,reject) => {
    httpbinInstance.request({
      url:'/tags/lists',
      method:'post',
      data:{
        ...queryform
      }
      }).then(res => {
        resolve(res)
      })
   })
}
// 添加标签列表
export const addNote = (queryform) => {
  return new Promise((resolve,reject) => {
    httpbinInstance.request({
      url:'/tags/add',
      method:'post',
      data:{
        ...queryform
      }
      }).then(res => {
        resolve(res)
      })
   })
}
// 添加货主
export const addOwner = (queryform) => {
  return new Promise((resolve,reject) => {
    httpbinInstance.request({
      url:'/owner/add',
      method:'post',
      data:{
        ...queryform
      }
      }).then(res => {
        resolve(res)
      })
   })
}
// 获取货主列表
export const getOwnerList = (queryform) => {
  return new Promise((resolve,reject) => {
    httpbinInstance.request({
      url:'/owner/lists',
      method:'post',
      data:{
        ...queryform
      }
      }).then(res => {
        resolve(res)
      })
   })
}
// 编辑货主
export const showOwner = (queryform) => {
  return new Promise((resolve,reject) => {
    httpbinInstance.request({
      url:'/owner/show',
      method:'post',
      data:{
        ...queryform
      }
      }).then(res => {
        resolve(res)
      })
   })
}
// 编辑货主
export const updateOwner = (queryform) => {
  return new Promise((resolve,reject) => {
    httpbinInstance.request({
      url:'/owner/update',
      method:'post',
      data:{
        ...queryform
      }
      }).then(res => {
        resolve(res)
      })
   })
}
// 删除货主
export const deleteOwner = (queryform) => {
  return new Promise((resolve,reject) => {
    httpbinInstance.request({
      url:'/owner/delete',
      method:'post',
      data:{
        ...queryform
      }
      }).then(res => {
        resolve(res)
      })
   })
}